//
//  StockVKLineVolumeBoxView.m
//  K线图自治
//
//  Created by LK-IOS on 2017/12/20.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "StockVKLineVolumeBoxView.h"
#import "UIColor+StockColorEntension.h"
@interface StockVKLineVolumeBoxView()

@property (nonatomic,strong) UILabel *volumeTextLabel;


@end

@implementation StockVKLineVolumeBoxView



-(void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    
    [self volumeTextLabel];
    
    
}
-(UILabel *)volumeTextLabel
{
    if (!_volumeTextLabel) {
        _volumeTextLabel = [[UILabel alloc] init];
        [self addSubview:_volumeTextLabel];
        _volumeTextLabel.text = @"成交量";
        _volumeTextLabel.textAlignment = NSTextAlignmentLeft;
        _volumeTextLabel.font = [UIFont systemFontOfSize:12];
        _volumeTextLabel.backgroundColor = [UIColor lightGrayColor];
        _volumeTextLabel.textColor = [UIColor blackColor];
        NSDictionary *attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor redColor] , NSBackgroundColorAttributeName :[UIColor lightGrayColor]};
        CGRect textRect = [self rectOfNSString:@"成交量" attribute:attribute];
        _volumeTextLabel.frame = CGRectMake(0, 0, textRect.size.width , textRect.size.height);
        
    }
    return _volumeTextLabel;
}

/**
 计算一个字段的宽高
 */
- (CGRect)rectOfNSString:(NSString *)string attribute:(NSDictionary *)attribute
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(MAXFLOAT, 0)
                                       options:NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin |
                   NSStringDrawingUsesFontLeading
                                    attributes:attribute
                                       context:nil];
    return rect;
}

@end
